package tresp.bthreads;

import java.util.logging.Logger;

import tresp.coordinator.ICoordinator;
import tresp.utils.BThreadVote;
import tresp.utils.ITankInfo;
import tresp.utils.logging.MyLogger;


/**
 * 
 * <b>Success</b>
 * 
 * <p>
 * 	This is the main b-thread with one porpose: success in the game 
 * 	(destroy the other tanks and stay alive)
 * </p>
 * 
 * 
 * @author<font color="blue">Maxim Kirilov</font>
 *
 */
public class Success extends BThread{

    private static Logger logger = MyLogger.getLogger( Success.class );
    
    private ITankInfo tankInfo;
    
    
    public Success(ICoordinator<BThreadVote> coordinator) {
	super(coordinator);
	logger.info("Success B-Thread created successfully");
	tankInfo = coordinator.getTankInfo();
    }


    @Override
    public void vote() {
	
	if ( tankInfo.getEnergy() > 80){
	    coordinator.vote(createBThreadVote(BThreadType.KILL, weight, 1D));
	    coordinator.vote(createBThreadVote(BThreadType.STAY_ALIVE, weight, -1D));
	}else if ( tankInfo.getEnergy() < 20){
	    coordinator.vote(createBThreadVote(BThreadType.KILL, weight, -1D));
	    coordinator.vote(createBThreadVote(BThreadType.STAY_ALIVE, weight, 1D));
	}
    }


    @Override
    public String getName() {
	return "Success";
    }



}
